home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / splint.zip / GETOPT.DOC < prev    next >
Text File  |  1993-05-19  |  3KB  |  63 lines

  1. /*
  2.   Parse the command line options, System V style.
  3.  
  4.   Standard option syntax is:
  5.  
  6.     option ::= SW [optLetter]* [argLetter space* argument]
  7.  
  8.   where
  9.     - SW is either '/' or '-', according to the current setting
  10.       of the MSDOS switchar (int 21h function 37h).
  11.     - there is no space before any optLetter or argLetter.
  12.     - opt/arg letters are alphabetic, not punctuation characters.
  13.     - optLetters, if present, must be matched in optionS.
  14.     - argLetters, if present, are found in optionS followed by ':'.
  15.     - argument is any white-space delimited string.  Note that it
  16.       can include the SW character.
  17.     - upper and lower case letters are distinct.
  18.  
  19.   There may be multiple option clusters on a command line, each
  20.   beginning with a SW, but all must appear before any non-option
  21.   arguments (arguments not introduced by SW).  Opt/arg letters may
  22.   be repeated: it is up to the caller to decide if that is an error.
  23.  
  24.   The character SW appearing alone as the last argument is an error.
  25.   The lead-in sequence SWSW ("--" or "//") causes itself and all the
  26.   rest of the line to be ignored (allowing non-options which begin
  27.   with the switch char).
  28.  
  29.   The string *optionS allows valid opt/arg letters to be recognized.
  30.   argLetters are followed with ':'.  Getopt () returns the value of
  31.   the option character found, or EOF if no more options are in the
  32.   command line.     If option is an argLetter then the global optarg is
  33.   set to point to the argument string (having skipped any white-space).
  34.  
  35.   The global optind is initially 1 and is always left as the index
  36.   of the next argument of argv[] which getopt has not taken.  Note
  37.   that if "--" or "//" are used then optind is stepped to the next
  38.   argument before getopt() returns EOF.
  39.  
  40.   If an error occurs, that is an SW char precedes an unknown letter,
  41.   then getopt() will return a '?' character and normally prints an
  42.   error message via perror().  If the global variable opterr is set
  43.   to false (zero) before calling getopt() then the error message is
  44.   not printed.
  45.  
  46.   For example, if the MSDOS switch char is '/' (the MSDOS norm) and
  47.  
  48.     *optionS == "A:F:PuU:wXZ:"
  49.  
  50.   then 'P', 'u', 'w', and 'X' are option letters and 'F', 'U', 'Z'
  51.   are followed by arguments.  A valid command line may be:
  52.  
  53.     aCommand  /uPFPi /X /A L someFile
  54.  
  55.   where:
  56.     - 'u' and 'P' will be returned as isolated option letters.
  57.     - 'F' will return with "Pi" as its argument string.
  58.     - 'X' is an isolated option.
  59.     - 'A' will return with "L" as its argument.
  60.     - "someFile" is not an option, and terminates getOpt.  The
  61.       caller may collect remaining arguments using argv pointers.
  62. */
  63.